<script setup>
import {useRoute,useRouter} from 'vue-router'
import {onMounted,ref,reactive } from 'vue'
import {findById} from '@/api/postInfo'
import {
  Document,
  User,
  Money,
  Clock,
  CollectionTag,
  Postcard,
  Briefcase,
  InfoFilled,
  TrendCharts,
  Back
} from '@element-plus/icons-vue'

const route =useRoute()
const router =useRouter()

onMounted(()=>{
    const id =route.query.id
    findById(id).then((res)=>{
        adminView.value=res.data
    })
})
const adminView =ref({})

const handleBack=()=>{
    router.back()
}

// 格式化日期时间
const formatDateTime = (dateString) => {
  if (!dateString) return ''
  const date = new Date(dateString)
  return date.toLocaleString()
}
const positionMap = reactive({
  1: '运营经理',
  2: '护工',
  3: '护士',
  4: '厨师',
  5: '行政人员',
  6: '医生',
  7: '其他'
});

</script>

<template>
  <div class="position-detail-container">
    <!-- 头部卡片 -->
    <el-card class="header-card" shadow="hover">
      <div class="header-content">
        <h1 class="page-title">
          <el-icon class="title-icon"><Document /></el-icon>
          岗位详细信息
        </h1>
        <div class="record-id">岗位编号: {{ adminView.positionId }}</div>
      </div>
    </el-card>

    <!-- 内容区域 -->
    <div class="content-container">
      <el-card class="info-card" shadow="never">
        <!-- 基本信息 -->
        <div class="info-section">
          <div class="section-header">
            <el-icon><InfoFilled /></el-icon>
            <h2>基本信息</h2>
          </div>
          <el-divider class="custom-divider" />
          <div class="info-grid">
            <div class="info-item">
              <span class="info-label">岗位名称：</span>
              <span class="info-value">
                <el-icon class="value-icon"><Postcard /></el-icon>
                {{ adminView.name }}
              </span>
            </div>
            <div class="info-item">
              <span class="info-label">岗位状态：</span>
              <el-tag :type="adminView.status === 1 ? 'success' : 'danger'" class="status-tag">
                {{ adminView.status === 1 ? '启用' : '禁用' }}
              </el-tag>
            </div>
            <div class="info-item full-width">
              <span class="info-label">岗位描述：</span>
              <span class="info-value">
                <el-icon class="value-icon"><InfoFilled /></el-icon>
                {{ adminView.description || '暂无描述' }}
              </span>
            </div>
            <div class="info-item full-width">
              <span class="info-label">任职要求：</span>
              <span class="info-value">
                <el-icon class="value-icon"><User /></el-icon>
                {{ adminView.requirements || '暂无要求' }}
              </span>
            </div>
          </div>
        </div>

        <!-- 薪资信息 -->
        <div class="info-section">
          <div class="section-header">
            <el-icon><Money /></el-icon>
            <h2>薪资信息</h2>
          </div>
          <el-divider class="custom-divider" />
          <div class="info-grid">
            <div class="info-item">
              <span class="info-label">基础薪资：</span>
              <span class="info-value highlight">
                <el-icon class="value-icon"><Money /></el-icon>
                {{ adminView.baseSalary }} 元
              </span>
            </div>
          </div>
        </div>

        <!-- 时间信息 -->
        <div class="info-section">
          <div class="section-header">
            <el-icon><Clock /></el-icon>
            <h2>时间信息</h2>
          </div>
          <el-divider class="custom-divider" />
          <div class="info-grid">
            <div class="info-item">
              <span class="info-label">创建时间：</span>
              <span class="info-value">
                <el-icon class="value-icon"><Clock /></el-icon>
                {{ formatDateTime(adminView.createTime) }}
              </span>
            </div>
            <div class="info-item">
              <span class="info-label">更新时间：</span>
              <span class="info-value">
                <el-icon class="value-icon"><Clock /></el-icon>
                {{ formatDateTime(adminView.updateTime) }}
              </span>
            </div>
          </div>
        </div>
      </el-card>

      <!-- 返回按钮 -->
      <div class="action-buttons">
        <el-button type="primary" @click="handleBack" class="back-button">
          <el-icon class="button-icon"><Back /></el-icon>
          返回
        </el-button>
      </div>
    </div>
  </div>
</template>
<style scoped>
.position-detail-container {
  padding: 20px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4edf9 100%);
  min-height: 100vh;
}

/* 头部卡片 */
.header-card {
  margin-bottom: 20px;
  border-radius: 16px;
  background: linear-gradient(120deg, #4a6bdf 0%, #3a56c4 100%);
  border: none;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(65, 105, 225, 0.25);
}

.header-content {
  display: flex;
  align-items: center;
  padding: 20px 30px;
  color: white;
}

.page-title {
  display: flex;
  align-items: center;
  font-size: 24px;
  font-weight: 600;
  margin: 0 15px 0 0;
  color: white;
}

.title-icon {
  font-size: 28px;
  color: #ffd04b;
  margin-right: 12px;
}

.record-id {
  margin-left: auto;
  font-size: 16px;
  opacity: 0.9;
}

/* 内容容器 */
.content-container {
  display: flex;
  flex-direction: column;
}

.info-card {
  border-radius: 16px;
  border: none;
  background: white;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  margin-bottom: 20px;
}

/* 信息区块 */
.info-section {
  padding: 25px 30px;
  border-bottom: 1px solid #f0f4f8;
}

.info-section:last-child {
  border-bottom: none;
}

.section-header {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.section-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
  margin-left: 10px;
}

.section-header .el-icon {
  font-size: 22px;
  color: #4a6bdf;
}

.custom-divider {
  margin: 10px 0 20px;
  background-color: #f0f4f8;
}

/* 信息网格布局 */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px 30px;
}

.info-item {
  display: flex;
  align-items: center;
  padding: 8px 0;
}

.full-width {
  grid-column: 1 / -1;
}

.info-label {
  font-weight: 500;
  color: #5a6d88;
  min-width: 100px;
  text-align: right;
  margin-right: 15px;
}

.info-value {
  font-weight: 500;
  color: #34495e;
  flex: 1;
  line-height: 1.6;
  display: flex;
  align-items: center;
}

.highlight {
  font-weight: 600;
  color: #4a6bdf;
}

.value-icon {
  margin-right: 8px;
  color: #4a6bdf;
}

/* 状态标签 */
.status-tag {
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 16px;
}

/* 操作按钮 */
.action-buttons {
  text-align: center;
  margin-top: 20px;
}

.back-button {
  width: 140px;
  height: 44px;
  font-size: 16px;
  font-weight: 500;
  border-radius: 8px;
  background: linear-gradient(120deg, #4a6bdf 0%, #3a56c4 100%);
  border: none;
  box-shadow: 0 4px 12px rgba(65, 105, 225, 0.3);
  transition: all 0.3s ease;
}

.back-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(65, 105, 225, 0.4);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .record-id {
    margin: 10px 0 0;
    align-self: flex-start;
  }
  
  .info-grid {
    grid-template-columns: 1fr;
  }
  
  .info-label {
    min-width: 90px;
    text-align: left;
  }
}
</style>